let app = getApp()

const dateUtil = require('../../utils/dateUtil')
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  userInfo: {
	    avatarUrl: '',
	    name: '',
	    gender: '',
	    age: '',
	    experience: '',
		address: '',
		phone: '',
	  },
	  jobStatusOptions: ['在职-暂不考虑', '在职-考虑机会', '离职-随时到岗'],
	  statusIndex: 1,
	  workExperiences: [
	  ],
	  educations: [
	  ],
	  skills: [],
	  certificates: [],
	  report: [],
	  evaluation: [],
	  idCardFront: '',
	  idCardBack: '',
	  imageList: [
	        'https://example.com/image1.jpg',
	        'https://example.com/image2.jpg',
	        'https://example.com/image3.jpg',
	        'https://example.com/image4.jpg'
	      ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
	new app.ToastPannel();
	
	var that = this
	// 加载保存的用户信息
	var key = wx.getStorageSync('key')
	var uid = wx.getStorageSync('u')
	var id = options.goods_id || ''
	wx.request({
	  url: app.configData.shop.api_url + '/index.php?ctl=Personal_Resume&met=resumeDetail&typ=json',
	  method: 'GET',
	  data: { k: key, u: uid, id: id },
	  header: {
	    'content-type': 'application/json'
	  },
	  success: function (res) {
		  console.log(res.data.data)
	    if (res.data.status == 200) {
			const user_info = {
				  avatarUrl: res.data.data.user_info.avatarUrl,
				  name: res.data.data.user_info.userName.charAt(0) + '**' || '-',
				  gender: res.data.data.user_info.gender == 1 ? '女' : '男',
				  age: dateUtil.getYearDiff(res.data.data.user_info.birthDate) || 0,
				  experience: dateUtil.getYearDiff(res.data.data.user_info.workDate) || 0,
				  address: res.data.data.user_info.region[0]+'/'+res.data.data.user_info.region[1]+'/'+res.data.data.user_info.region[2]
			}
			that.setData({
				userInfo: user_info,
				educations: res.data.data.education_info,
				workExperiences: res.data.data.job_info,
				idCardFront: res.data.data.idCardFront,
				idCardBack:  res.data.data.idCardBack,
				certificates: res.data.data.certification_info,
				report: res.data.data.report_info,
				evaluation: res.data.data.evaluation,
			})
			
			console.log(that.data.report)
			console.log(that.data.imageList)
	    } else {
	      that.show('数据加载失败')
	    }
	  
	  }
	})
  },
  // 预览图片
   previewImageCertificates(e) {
     const currentIndex = e.currentTarget.dataset.index;
  	 
  	 // 转换为URL数组
  	 const urlArray = this.data.certificates.map(item => item.path);
     wx.previewImage({
       current: urlArray[currentIndex], // 当前显示图片的http链接
       urls: urlArray // 需要预览的图片http链接列表
     });
   },
  // 预览图片
   previewImageReport(e) {
     const currentIndex = e.currentTarget.dataset.index;
	 // 转换为URL数组
	 const urlArray = this.data.report.map(item => item.path);
     wx.previewImage({
       current: urlArray[currentIndex], // 当前显示图片的http链接
       urls: urlArray // 需要预览的图片http链接列表
     });
   },
   // 预览图片
    previewImageUser() {
      wx.previewImage({
        current: this.data.userInfo.avatarUrl, // 当前显示图片的http链接
	    urls: [this.data.userInfo.avatarUrl] // 需要预览的图片http链接列表
      });
      
    },
})